﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.OA;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.OA.Pages
{
    public partial class DocFolder_Create : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String pid = Request.QueryString["parentId"] ?? String.Empty;
            if (!IsPostBack)
            {
                this.txt_parentId.Text = pid;
            }
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            String pid = Request.QueryString["parentId"] ?? String.Empty;
            DocItem doc = new DocItem();
            if (pid == "")
            {
                doc.ParentId = null;
            }
            else
            {
                doc.ParentId = new Guid(pid);
            }
            doc.Id = Guid.NewGuid();
            doc.TypeCaption = DocItem.Folder;
            doc.TypeCode = DocItem.Folder;
            doc.Code = txt_Code.Text;
            doc.Caption = txt_Caption.Text;
            doc.Description = txt_Description.Text;
            doc.CreatedDate = DateTime.Now;
            doc.Creator = this.User.Identity.Name;

            OAService server = new OAService();

            ServiceResult result = server.SaveDocItem(doc);

            if (result.IsSuccess)
            {
                Response.Redirect("DocItem-List.aspx?parentId=" + pid);
            }
        }

        protected void btn_Cannel_Click(object sender, EventArgs e)
        {
            String pid = Request.QueryString["parentId"] ?? String.Empty;
            Response.Redirect("DocItem-List.aspx?parentId=" + pid);
        }
    }
}